﻿<Window x:Class="SimCityPak.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:simCityPak="clr-namespace:SimCityPak"
        xmlns:AdvancedEditors="clr-namespace:SimCityPak.Views.AdvancedEditors"
        Title="SimCityPak" Height="800" Width="1024" Loaded="Window_Loaded" WindowStartupLocation="CenterScreen" WindowState="Normal" Closing="Window_Closing" Icon="/SimCityPak;component/Images/SCP_icon.ico">
    <Window.Resources>
        <simCityPak:InstanceTypeIconConverter x:Key="IconConverter" />
        <ContextMenu x:Key="rowContextMenu" Opened="ContextMenu_Opened">
            <MenuItem Header="Export..." Name="mnuExportInstance" Click="mnuExportInstance_Click" />
            <MenuItem Header="Export to Package..." Name="mnuExportPackage" Click="mnuExportPackage_Click"  />
            <MenuItem Header="Advanced Export..." Name="mnuExportCopy" Click="mnuExportCopy_Click"  />
            <MenuItem Header="Delete" Name="mnuDeleteInstance" IsCheckable="True" IsChecked="{Binding Path=Deleted, UpdateSourceTrigger=PropertyChanged}"/>
            <MenuItem Header="Edit TGI Information..." Name="mnuEditTGI"  Click="mnuEditTGI_Click" />
            <MenuItem Header="Change Instance Name..." Name="mnuInstanceName" Click="mnuInstanceName_Click"  />
            <MenuItem Header="Copy" Click="mnuCopyKey_Click">
                <MenuItem Header="Key (T-G-I)" Name="mnuCopyKey" Click="mnuCopyKey_Click"/>
                <MenuItem Header="TypeID" Name="mnuCopyType" Click="mnuCopyType_Click" />
                <MenuItem Header="GroupContainer" Name="mnuCopyGroup" Click="mnuCopyGroup_Click" />
                <MenuItem Header="InstanceID" Name="mnuCopyInstance" Click="mnuCopyInstance_Click" />
            </MenuItem>
            <MenuItem Header="Filter by">
                <MenuItem Header="Type" Name="mnuFilterType" Click="mnuFilterType_Click"/>
                <MenuItem Header="Group" Name="mnuFilterGroup" Click="mnuFilterGroup_Click" />
                <MenuItem Header="Instance" Name="mnuFilterInstance" Click="mnuFilterInstance_Click" />
            </MenuItem>
            <MenuItem Header="Search PROPs with Instance" Name="mnuSearchPROPIID" Click="mnuSearchPROPIID_Click"/>
            <MenuItem Header="Open in new window" Name="mnuOpenInNewWindow" Click="mnuOpenInNewWindow_Click"/>
        </ContextMenu>
        <ContextMenu x:Key="packageRowContextMenu">
            <MenuItem Name="mnuSave" Header="Save" Click="mnuSave_Click"  />
            <MenuItem Name="mnuSaveAs" Header="Save As..." Click="mnuSaveAs_Click"  />
            <MenuItem Name="mnuClose" Header="Close" Click="mnuClose_Click"/>
            <MenuItem Header="Import..." Name="mnuImportInstance" Click="mnuImportInstance_Click"/>
        </ContextMenu>
        <Style x:Key="DefaultRowStyle" TargetType="{x:Type DataGridRow}">
            <Setter Property="ContextMenu" Value="{StaticResource rowContextMenu}" />
            <Style.Triggers>
                <DataTrigger Binding="{Binding Deleted}" Value="true">
                    <Setter Property="Background" Value="Red"/>
                </DataTrigger>
                <DataTrigger Binding="{Binding IsModified}" Value="true">
                    <Setter Property="Background" Value="Yellow"/>
                </DataTrigger>
            </Style.Triggers>
        </Style>
        <Style x:Key="DefaultPackageRowStyle" TargetType="{x:Type DataGridRow}">
            <Setter Property="ContextMenu" Value="{StaticResource packageRowContextMenu}" />
            <Style.Triggers>
                <DataTrigger Binding="{Binding IsModified}" Value="true">
                    <Setter Property="Background" Value="Yellow"/>
                </DataTrigger>
            </Style.Triggers>
        </Style>
    </Window.Resources>
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto" />
            <RowDefinition Height="*" />
            <RowDefinition Height="auto" />
        </Grid.RowDefinitions>
        <Menu Grid.Row="0" Height="23" Name="mainMenu" VerticalAlignment="Top">
            <MenuItem Header="File">
                <MenuItem Header="Open packages..." Click="OpenPackages_click" />
                <MenuItem Header="Add packages..." Click="AddPackages_click" />
                <Separator/>
                <MenuItem Header="Reload packages" Click="ReloadPackages_click" />
                <MenuItem Header="Close all packages" Click="CloseAllPackages_click" />
                <Separator/>
                <MenuItem Header="Exit" Click="Exit_click" />
            </MenuItem>
            <MenuItem Header="Search">
                <MenuItem Header="Properties" Name="mnuSearchPROP" Click="mnuSearchPROP_Click" IsEnabled="False" />
                <!--<MenuItem Header="Invalid FNV names" Name="mnuSearchInvalidFnvNames" Click="mnuSearchInvalidFnvNames_Click" IsEnabled="False" />-->
            </MenuItem>
            <MenuItem Header="Settings" Name="mnuSettings" Click="mnuSettings_Click" />
            <MenuItem Header="Tools" >
                <MenuItem Header="SQL Export/Import" Name="mnuSQLExportImport" Click="mnuSQLExportImport_Click" />
                <MenuItem Header="FNV Tools">
                    <MenuItem Header="FNV Calculator" Name="mnuFNV" Click="mnuFNV_Click" />
                    <MenuItem Header="FNV Dictionary Generator" Name="mnuFNVNameHashScanner" Click="mnuFNVNameHashScanner_Click" IsEnabled="True" />
                    <MenuItem Header="FNV Dictionary Importer" Name="mnuFNVNameHashImport" Click="mnuFNVNameHashImport_Click" IsEnabled="True" />
                </MenuItem>
                <MenuItem Header="Add Property Descriptor" Name="mnuProperty" Click="mnuProperty_Click" />
                <MenuItem Header="Scan for Instances unused in PROPs" Name="mnuScan" Click="mnuScan_Click" IsEnabled="True" />
                <MenuItem Header="Deploy Scripts Mods..." Name="mnuDeployScripts" Visibility="Collapsed" IsEnabled="True" Click="mnuDeployScripts_Click" />
                <MenuItem Header="Load Instance Names from Locale File..." Name="mnuInstanceIds" IsEnabled="True" Click="mnuInstanceIds_Click" />
            </MenuItem>
            <MenuItem Header="About"  Name="mnuAbout" Click="mnuAbout_Click" />
        </Menu>
        <Grid Grid.Row="1" HorizontalAlignment="Stretch">
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="350" MinWidth="200" />
                <ColumnDefinition Width="4" />
                <ColumnDefinition Width="*" MinWidth="200"/>
            </Grid.ColumnDefinitions>

            <TabControl Name="tabControl1">
                <TabItem Header="Files" Name="tabItem1">
                    <Grid>
                        <Grid.RowDefinitions>
                            <RowDefinition Height="Auto"/>
                            <RowDefinition Height="*" />
                        </Grid.RowDefinitions>

                        <Grid>
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="*" />
                                <ColumnDefinition Width="*"/>
                                <ColumnDefinition Width="*"/>
                                <ColumnDefinition Width="*"/>
                            </Grid.ColumnDefinitions>
                            <ComboBox Grid.Column="0" Margin="4" Name="comboboxTypes" MinWidth="50"  SelectionChanged="filterCombobox_SelectionChanged" >
                                <ComboBox.ItemTemplate>
                                    <DataTemplate>
                                        <StackPanel Orientation="Horizontal">
                                            <Image Source="{Binding HexIdValue, Converter={StaticResource ResourceKey=IconConverter}}" Height="16" Width="16" Stretch="Uniform" Margin="0,0,5,0" />
                                            <TextBlock Text="{Binding DisplayName}" />
                                        </StackPanel>
                                    </DataTemplate>
                                </ComboBox.ItemTemplate>
                            </ComboBox>
                            <ComboBox Grid.Column="1" Margin="4" Name="comboboxGroups" MinWidth="50" DisplayMemberPath="DisplayName" IsEditable="True" SelectionChanged="filterCombobox_SelectionChanged" TextBoxBase.TextChanged="filterTextBoxes_TextChanged" />
                            <ComboBox Grid.Column="2" Margin="4" Name="comboboxInstances" MinWidth="50" DisplayMemberPath="DisplayName" IsEditable="True" SelectionChanged="filterCombobox_SelectionChanged" TextBoxBase.TextChanged="filterTextBoxes_TextChanged" />
                            <Button Grid.Column="3" Margin="4" Content="Clear Filter" MinWidth="50" Name="btnClearFilter" Click="btnClearFilter_Click" />
                        </Grid>

                        <DataGrid Grid.Row="1"  AutoGenerateColumns="False" IsReadOnly="True" RowStyle="{StaticResource DefaultRowStyle}" Name="dataGridInstances" Margin="5" SelectionChanged="dataGridInstances_SelectionChanged" Sorting="dataGridInstances_Sorting" HorizontalGridLinesBrush="#FFA3A3A3" VerticalGridLinesBrush="#FFA3A3A3" MouseDoubleClick="dataGridInstances_MouseDoubleClick" HeadersVisibility="Column" GridLinesVisibility="Horizontal">
                            <DataGrid.Columns>
                                <DataGridTemplateColumn Width="18" CanUserResize="False" Header="" SortMemberPath="TypeId">
                                    <DataGridTemplateColumn.CellTemplate>
                                        <DataTemplate>
                                            <Image Source="{Binding Converter={StaticResource ResourceKey=IconConverter}}" Height="16" Width="16" Stretch="Uniform" ToolTip="{Binding TypeName}" />
                                        </DataTemplate>
                                    </DataGridTemplateColumn.CellTemplate>
                                </DataGridTemplateColumn>
                                <DataGridTextColumn Width="*" Visibility="Hidden"  Header="Group Container" Binding="{Binding TypeName, StringFormat=X}" FontFamily="Courier New" />
                                <DataGridTemplateColumn Width="*" Header="Instance" SortMemberPath="InstanceName">
                                    <DataGridTemplateColumn.CellTemplate>
                                        <DataTemplate>
                                            <TextBlock Text="{Binding InstanceName}" ToolTip="{Binding InstanceFullName}" />
                                        </DataTemplate>
                                    </DataGridTemplateColumn.CellTemplate>
                                </DataGridTemplateColumn>
                                <DataGridCheckBoxColumn Width="*" Visibility="Hidden"  Header="Compressed" Binding="{Binding Compressed}" />
                                <DataGridTemplateColumn Width="80" Header="Size" SortMemberPath="CompressedSize"  >
                                    <DataGridTemplateColumn.CellTemplate>
                                        <DataTemplate>
                                            <TextBlock Text="{Binding CompressedSize}" TextAlignment="Right" Margin="0,0,5,0" />
                                        </DataTemplate>
                                    </DataGridTemplateColumn.CellTemplate>
                                </DataGridTemplateColumn>
                                <DataGridCheckBoxColumn Width="*" Visibility="Hidden"  Header="Modified" Binding="{Binding IsModified}" />
                            </DataGrid.Columns>
                        </DataGrid>
                    </Grid>
                </TabItem>
                <TabItem Header="Packages" Name="tabItem2">
                    <Grid>
                        <DataGrid AutoGenerateColumns="False" HeadersVisibility="Column" RowStyle="{StaticResource DefaultPackageRowStyle}" HorizontalGridLinesBrush="#FFA3A3A3" Margin="5" Name="packageDataGrid" IsReadOnly="True" GridLinesVisibility="Horizontal">
                            <DataGrid.Columns>
                                <DataGridTemplateColumn Width="18" CanUserResize="False" Header="" SortMemberPath="TypeId">
                                    <DataGridTemplateColumn.CellTemplate>
                                        <DataTemplate>
                                            <Image Source="/SimCityPak;component/Images/package.png" Height="16" Width="16" Stretch="Uniform" />
                                        </DataTemplate>
                                    </DataGridTemplateColumn.CellTemplate>
                                </DataGridTemplateColumn>
                                <DataGridTextColumn Binding="{Binding FileName}" Header="Filename" Width="*" IsReadOnly="True" />
                            </DataGrid.Columns>
                        </DataGrid>
                    </Grid>
                </TabItem>
            </TabControl>
            <GridSplitter Grid.Column="1" Width="3"  ResizeDirection="Columns" HorizontalAlignment="Center" VerticalAlignment="Stretch"/>
            <TextBlock Grid.Column="2" Text="{Binding ElementName=dataGridInstances, Path=SelectedItem.InstanceFullName}" FontWeight="Bold" TextAlignment="Center" Margin="5" VerticalAlignment="Top"  Height="20"  />
            <TabControl Grid.Column="2" Margin="0,30,0,0" Name="tablControlView" >
                <TabItem Header="Context View">
                    <ContentControl Grid.Column="1" Name="viewContainer">
                        <ContentControl.ContentTemplateSelector>
                            <simCityPak:ViewSelector />
                        </ContentControl.ContentTemplateSelector>
                        <ContentControl.Resources>
                            <DataTemplate DataType="{x:Type simCityPak:DatabaseIndexData}" x:Key="viewRawImage">
                                <simCityPak:ViewRawImage />
                            </DataTemplate>
                            <DataTemplate DataType="{x:Type simCityPak:DatabaseIndexData}" x:Key="viewPng">
                                <simCityPak:ViewPng />
                            </DataTemplate>
                            <DataTemplate DataType="{x:Type simCityPak:DatabaseIndexData}" x:Key="viewTga">
                                <simCityPak:ViewTga />
                            </DataTemplate>
                            <DataTemplate DataType="{x:Type simCityPak:DatabaseIndexData}" x:Key="viewRW4">
                                <simCityPak:ViewRW4 />
                            </DataTemplate>
                            <DataTemplate DataType="{x:Type simCityPak:DatabaseIndexData}" x:Key="viewData">
                                <simCityPak:ViewHex />
                            </DataTemplate>
                            <DataTemplate DataType="{x:Type simCityPak:DatabaseIndexData}" x:Key="viewText">
                                <simCityPak:ViewText />
                            </DataTemplate>
                            <DataTemplate DataType="{x:Type simCityPak:DatabaseIndexData}" x:Key="viewJavascript">
                                <simCityPak:ViewJavaScript />
                            </DataTemplate>
                            <DataTemplate DataType="{x:Type simCityPak:DatabaseIndexData}" x:Key="viewPropertyFile">
                                <simCityPak:ViewPropertyFile />
                            </DataTemplate>
                            <DataTemplate DataType="{x:Type simCityPak:DatabaseIndexData}" x:Key="viewRaster">
                                <simCityPak:ViewRaster />
                            </DataTemplate>
                            <DataTemplate DataType="{x:Type simCityPak:DatabaseIndexData}" x:Key="viewDecalDictionary">
                                <AdvancedEditors:ViewDecalDictionary />
                            </DataTemplate>
                            <DataTemplate DataType="{x:Type simCityPak:DatabaseIndexData}" x:Key="viewPath">
                                <AdvancedEditors:ViewPath />
                            </DataTemplate>
                        </ContentControl.Resources>
                    </ContentControl>
                </TabItem>
                <TabItem Header="Hex View">
                    <simCityPak:ViewHex x:Name="viewHexContainer" />
                </TabItem>
            </TabControl>
        </Grid>
        <StatusBar Grid.Row="2" Height="23" Name="statusBar1" VerticalAlignment="Bottom"/>
    </Grid>
</Window>
